package Servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

@WebServlet("/delete")
public class delete extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String name = request.getParameter("name");
        Connection conn = null;
        PreparedStatement ps = null;
        try {
            conn = JDBCutil.getConnection();
            ps = conn.prepareStatement("delete from t_birthday where name = ?");
            ps.setString(1,name);
            ps.executeUpdate();
        } catch (SQLException | ClassNotFoundException throwables) {
            throwables.printStackTrace();
        }finally {
            JDBCutil.closeRs(null,ps,conn);
        }
        //完成更新，重定向到show界面
        String contextPath = request.getContextPath();
        response.sendRedirect(contextPath+"/getBirth");//重定向无需加项目名
    }
}
